package com.xinzhi.savingpot.rminfo.service.impl;

import com.xinzhi.savingpot.rminfo.mapper.IRecordinfoMapper;
import com.xinzhi.savingpot.rminfo.pojo.RecordinfoVo;
import com.xinzhi.savingpot.rminfo.service.IRecordinfoService;
import com.xinzhi.savingpot.userinfo.entity.UserInfo;
import com.xinzhi.savingpot.util.BaseResponse;
import com.xinzhi.savingpot.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;

@Service
public class RecordinfoImpl implements IRecordinfoService {
    @Autowired
    IRecordinfoMapper iRecordinfoMapper;
    @Autowired
    RedisUtil redisUtil;
    @Autowired
    RecordinfoAllImpl recordinfoAll;
    @Autowired
    LimitAllImpl limitAll;

    @Override
    public BaseResponse findRecordinfoById(int userid) {
        RecordinfoVo rev = new RecordinfoVo();
        Integer shops = 24;
        if (!redisUtil.hasKey("Recordinfo-" + userid)) {
            UserInfo recordinfo = iRecordinfoMapper.getRecordinfo(userid);
            if (recordinfo != null) {
                Integer shoppoints = recordinfo.getShoppoints();
                rev.setShoppoints(shoppoints);
                Integer points = shops - shoppoints;
                rev.setPoints(points);
                redisUtil.set("Recordinfo-" + userid, rev, 6000);
                return new BaseResponse(200, "查询成功", rev);
            } else {
                return new BaseResponse(400, "查询失败", null);
            }
        }
        return new BaseResponse(200, "查询成功", redisUtil.hasKey("Recordinfo-" + userid));


    }
}